package map.android.baidu.carpool.utils;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;

public class DateUtil {
	// 时间转化方法
	static DateFormat datetimeFormat = new SimpleDateFormat(	"yyyy年MM月dd日  HH:mm");
	static  DateFormat dateFormat = new SimpleDateFormat("yyyy年MM月dd日");  
	static  DateFormat timeFormat = new SimpleDateFormat("HH:mm");  
	static Date mDate = new Date();
	static TimeZone mTimeZone = TimeZone.getTimeZone("GMT+8:00");

	static  DateFormat dateCreateFormatCoupon = new SimpleDateFormat("yyyy.MM.dd");
	static  DateFormat dateExprieFormatCoupon = new SimpleDateFormat("MM.dd");
	public static String getDate(long createTime) {
		String result = null;
		try {
			datetimeFormat.setTimeZone(mTimeZone);
			mDate.setTime(createTime*1000);
			result = datetimeFormat.format(mDate);

		} catch (Exception e) {
			return Long.toString(createTime);
		}
		return result;
	}
	public static String getDate(String createTime) {
		String result = null;
		try {
			datetimeFormat.setTimeZone(mTimeZone);
			mDate.setTime(SafeUtils.safeString2long(createTime)*1000);
			result = datetimeFormat.format(mDate);

		} catch (Exception e) {
			return createTime;
		}
		return result;
	}
	public static String getDateFormat(long createTime) {
		String result = null;
		try {
			dateFormat.setTimeZone(mTimeZone);
			mDate.setTime(createTime*1000);
			result = dateFormat.format(mDate);

		} catch (Exception e) {
			return Long.toString(createTime);
		}
		return result;
	}
	
	public static String getDateFormat(String createTime) {
		String result = null;
		try {
			dateFormat.setTimeZone(mTimeZone);
			mDate.setTime(SafeUtils.safeString2long(createTime)*1000);
			result = dateFormat.format(mDate);

		} catch (Exception e) {
			return createTime;
		}
		return result;
	}
	public static String getTimeFormat(long createTime) {
		String result = null;
		try {
			timeFormat.setTimeZone(mTimeZone);
			mDate.setTime(createTime*1000);
			result = timeFormat.format(mDate);
			
		} catch (Exception e) {
			return Long.toString(createTime);
		}
		return result;
	}
	
	public static String getTimeFormat(String createTime) {
		String result = null;
		try {
			timeFormat.setTimeZone(mTimeZone);
			mDate.setTime(SafeUtils.safeString2long(createTime)*1000);
			result = timeFormat.format(mDate);
			
		} catch (Exception e) {
			return createTime;
		}
		return result;
	}
	
	public static String getDateFormatCreateUsCoupon(String createTime) {
        String result = null;
        try {
            dateCreateFormatCoupon.setTimeZone(mTimeZone);
            mDate.setTime(SafeUtils.safeString2long(createTime)*1000);
            result = dateCreateFormatCoupon.format(mDate);

        } catch (Exception e) {
            return createTime;
        }
        return result;
    }
	
	public static String getDateFormatExprieUsCoupon(String createTime) {
        String result = null;
        try {
            dateExprieFormatCoupon.setTimeZone(mTimeZone);
            mDate.setTime(SafeUtils.safeString2long(createTime)*1000);
            result = dateExprieFormatCoupon.format(mDate);

        } catch (Exception e) {
            return createTime;
        }
        return result;
    }
}
